<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:aw="clr-namespace:Assergs.Windows"
    xmlns:awc="clr-namespace:Assergs.Windows.Controls"
    >

    <SolidColorBrush x:Key="ForegroundBrush" Color="{x:Static aw:SearchableComboBoxPallet.Foreground}"></SolidColorBrush>
    <SolidColorBrush x:Key="NormalBorderBrush" Color="{x:Static aw:SearchableComboBoxPallet.NormalBorder}"></SolidColorBrush>
    <SolidColorBrush x:Key="GlyphBrush" Color="{x:Static aw:SearchableComboBoxPallet.Glyph}" />
    <SolidColorBrush x:Key="LightBorderBrush" Color="{x:Static aw:SearchableComboBoxPallet.LightBorder}"/>
    <SolidColorBrush x:Key="PlusLightBorderBrush" Color="{x:Static aw:SearchableComboBoxPallet.PlusLightBorder}"/>
    <SolidColorBrush x:Key="EditableControlBackgroundBrush" Color="{x:Static aw:SearchableComboBoxPallet.EditableControlBackground}"/>
    
    <LinearGradientBrush x:Key="NormalBackGroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:SearchableComboBoxPallet.NormalBackGround1}" Offset="0"/>
        <GradientStop Color="{x:Static aw:SearchableComboBoxPallet.NormalBackGround2}" Offset="0.4"/>
        <GradientStop Color="{x:Static aw:SearchableComboBoxPallet.NormalBackGround3}" Offset="0.4"/>
        <GradientStop Color="{x:Static aw:SearchableComboBoxPallet.NormalBackGround4}" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="LightBackGroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Offset="0" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlMouseOver1}" />
        <GradientStop Offset="0.4" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlMouseOver2}" />
        <GradientStop Offset="0.4" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlMouseOver3}" />
        <GradientStop Offset="1" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlMouseOver4}" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PlusLightBackGroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Offset="0" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlPressed1}" />
        <GradientStop Offset="0.1" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlPressed2}" />
        <GradientStop Offset="0.4" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlPressed3}" />
        <GradientStop Offset="0.4" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlPressed4}" />
        <GradientStop Offset="1" Color="{x:Static aw:SearchableComboBoxPallet.DefaultControlPressed5}" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="DisableBackGroundBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="{x:Static aw:SearchableComboBoxPallet.DisableBackGround1}"></GradientStop>
        <GradientStop Color="{x:Static aw:SearchableComboBoxPallet.DisableBackGround2}"></GradientStop>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="DisabledBorderBrush" Color="{x:Static aw:SearchableComboBoxPallet.DisabledBorder}"/>
    <SolidColorBrush x:Key="DisabledForegroundBrush" Color="{x:Static aw:SearchableComboBoxPallet.DisabledForeground}"/>
        
    <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="18"/>
			</Grid.ColumnDefinitions>
			<Rectangle Grid.Column="0" Fill="Transparent"/>
			<Border 
			  Name="_ToggleButtonBorder"
			  Grid.Column="1"
			  CornerRadius="0"
			  Background="{StaticResource NormalBackGroundBrush}"
			  BorderBrush="{StaticResource NormalBorderBrush}"
			  BorderThickness="0,1,0,1"/>
			<Path 
			  Name="_Arrow"
			  Grid.Column="1"
			  Fill="{StaticResource GlyphBrush}"
			  HorizontalAlignment="Center"
			  VerticalAlignment="Center"
			  Data="M 0 0 L 3 3 L 6 0 Z"/>
		</Grid>
		<ControlTemplate.Triggers>
			<Trigger Property="IsMouseOver" Value="true">
				<Setter TargetName="_ToggleButtonBorder" Property="Background" Value="{StaticResource LightBackGroundBrush}" />
				<!--<Setter TargetName="_ToggleButtonBorder" Property="BorderBrush" Value="{StaticResource LightBorderBrush}" />-->
			</Trigger>
			<Trigger Property="IsChecked" Value="true">
				<Setter TargetName="_ToggleButtonBorder" Property="Background" Value="{StaticResource PlusLightBackGroundBrush}" />
				<!--<Setter TargetName="_ToggleButtonBorder" Property="BorderBrush" Value="{StaticResource LightBorderBrush}" />-->
			</Trigger>
			<Trigger Property="IsEnabled" Value="False">
				<Setter TargetName="_ToggleButtonBorder" Property="Background" Value="{StaticResource DisableBackGroundBrush}" />
				<Setter TargetName="_ToggleButtonBorder" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
				<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
				<Setter TargetName="_Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}" />
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	
	<ControlTemplate x:Key="SeachButtonTemplate" TargetType="Button"> 
		<Border 
			Name="_SearchButtonBorder"
			CornerRadius="0,2,2,0"
			Background="{StaticResource NormalBackGroundBrush}"
			BorderBrush="{StaticResource NormalBorderBrush}"
			BorderThickness="1">
			<Image Name="_SearchImage" Stretch="None" Source="../resources/Magnifier16.png" />
		</Border>
		<ControlTemplate.Triggers>
			<Trigger Property="IsMouseOver" Value="true">
				<Setter TargetName="_SearchButtonBorder" Property="Background" Value="{StaticResource LightBackGroundBrush}" />
				<!--<Setter TargetName="_SearchButtonBorder" Property="BorderBrush" Value="{StaticResource LightBorderBrush}" />-->
			</Trigger>
			<Trigger Property="IsPressed" Value="true">
				<Setter TargetName="_SearchButtonBorder" Property="Background" Value="{StaticResource PlusLightBackGroundBrush}" />
				<!--<Setter TargetName="_SearchButtonBorder" Property="BorderBrush" Value="{StaticResource LightBorderBrush}" />-->
			</Trigger>
			<Trigger Property="IsEnabled" Value="False">
				<Setter TargetName="_SearchButtonBorder" Property="Background" Value="{StaticResource DisableBackGroundBrush}" />
				<Setter TargetName="_SearchButtonBorder" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
				<Setter TargetName="_SearchImage" Property="Opacity" Value="0.5" />
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
    

    <Style x:Key="{x:Type awc:SearchableComboBox}" TargetType="{x:Type awc:SearchableComboBox}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="IsEditable" Value="True"/>
        <Setter Property="StaysOpenOnEdit" Value="True"/>
        <Setter Property="IsTextSearchEnabled" Value="False"/>
        <Setter Property="MinHeight" Value="22"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type awc:SearchableComboBox}">
                    <Grid>
                    
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="18" />
                            <ColumnDefinition Width="22" />
                        </Grid.ColumnDefinitions>
                        
                        <Border
                            x:Name="BorderLeft"
                            Grid.Column="0"
                            CornerRadius="2,0,0,2"
                            Background="{StaticResource EditableControlBackgroundBrush}"
                            BorderBrush="{StaticResource NormalBorderBrush}"
                            BorderThickness="1" />

                        <ToggleButton
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            Name="PART_ToggleButton"
                            Focusable="false"
                            IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                            ClickMode="Press"
                            Template="{StaticResource ComboBoxToggleButton}">
                        </ToggleButton>
                        
                        <Button MinWidth="0"
							Grid.Column="2"
							Name="PART_SearchButton"
							FocusManager.IsFocusScope="True"
							Template="{StaticResource SeachButtonTemplate}">
                        </Button>

                        <ContentPresenter
                            Grid.Column="0"
                            Name="ContentSite"
                            IsHitTestVisible="False"
                            Content="{TemplateBinding SelectionBoxItem}"
                            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                            Margin="3,3,23,3"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Left" />

                        <TextBox Name="PART_EditableTextBox"
                          Grid.Column="0"
                          BorderThickness="0"
                          BorderBrush="Transparent"
                          HorizontalAlignment="Left"
                          VerticalAlignment="Center"
                          Margin="1,2,1,1"
                          Focusable="True"
                          Background="Transparent"
                          Visibility="Hidden"
                          Foreground="{StaticResource ForegroundBrush}"
                          IsReadOnly="{TemplateBinding IsReadOnly}"
                          FocusManager.IsFocusScope="True"/>

                        <Popup
                          Grid.ColumnSpan="2"
                          Name="PART_Popup"
                          Placement="Bottom"
                          IsOpen="{TemplateBinding IsDropDownOpen}"
                          AllowsTransparency="True"
                          Focusable="False"
                          PopupAnimation="None"
                          VerticalOffset="0">
                            <Grid
								Name="DropDown"
								SnapsToDevicePixels="True"
								MinWidth="{TemplateBinding ActualWidth}"
								MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                <Border
									Name="DropDownBorder"
									Background="{StaticResource EditableControlBackgroundBrush}"
									BorderThickness="1"
									CornerRadius="0"
									BorderBrush="{StaticResource NormalBorderBrush}"/>
                                <ScrollViewer Margin="4" SnapsToDevicePixels="True">
                                    <StackPanel Name="_ItemsContainer" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                        
                        <TextBlock Background="{StaticResource EditableControlBackgroundBrush}" VerticalAlignment="Center" Margin="4,0,4,0" Name="_LoadingTextBlock" Text="Carregando itens..." Visibility="Collapsed" />

                    </Grid>
                    <ControlTemplate.Triggers>
						<Trigger Property="IsLoading" Value="True">
							<Setter Property="IsEnabled" Value="false"/>
                            <Setter TargetName="_LoadingTextBlock" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="PART_ToggleButton" Property="IsChecked" Value="False"/>
                            <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Collapsed"/>
                        </Trigger>                    
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            <Setter TargetName="BorderLeft" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}"/>
                        </Trigger>
                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                        <Trigger SourceName="PART_Popup" Property="Popup.AllowsTransparency" Value="true">
                            <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
                            <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                        </Trigger>
                        <Trigger Property="IsEditable" Value="true">
                            <Setter Property="IsTabStop" Value="false"/>
                            <Setter TargetName="PART_EditableTextBox" Property="Visibility"	Value="Visible"/>
                            <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="PART_ToggleButton" Property="Grid.Column" Value="1"/>
                            <Setter TargetName="PART_ToggleButton" Property="Grid.ColumnSpan" Value="1"/>
                        </Trigger>
                    
						      
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
        </Style.Triggers>
    </Style>
    
</ResourceDictionary>